package com.d3works.apps.project.web;

import com.d3works.apps.project.db.Project;
import com.d3works.apps.project.db.repo.ProjectRepository;
import com.d3works.apps.project.service.ProjectMenuService;
import com.d3works.exception.service.TraceBackService;
import com.d3works.inject.Beans;
import com.d3works.rpc.ActionRequest;
import com.d3works.rpc.ActionResponse;

public class ProjectMenuController {

  public void allOpenProjectTasks(ActionRequest request, ActionResponse response) {
    response.setView(Beans.get(ProjectMenuService.class).getAllOpenProjectTasks());
  }

  public void allOpenProjectTickets(ActionRequest request, ActionResponse response) {
    response.setView(Beans.get(ProjectMenuService.class).getAllOpenProjectTickets());
  }

  public void allProjects(ActionRequest request, ActionResponse response) {
    response.setView(Beans.get(ProjectMenuService.class).getAllProjects());
  }

  public void allProjectTasks(ActionRequest request, ActionResponse response) {
    response.setView(Beans.get(ProjectMenuService.class).getAllProjectTasks());
  }

  public void allProjectRelatedTasks(ActionRequest request, ActionResponse response) {

    try {
      Project project = request.getContext().asType(Project.class);
      project = Beans.get(ProjectRepository.class).find(project.getId());
      response.setView(Beans.get(ProjectMenuService.class).getAllProjectRelatedTasks(project));
    } catch (Exception e) {
      TraceBackService.trace(response, e);
    }
  }
}
